<template>
  <div class="create_container">
    <div class="add-form-box">
      <el-form ref="form" :model="form_add" label-width="80px" :inline="false">
        <template v-for="(item,index) in columnArr" :key="index">
          <template v-if="item.add || item.add == undefined">
            <el-form-item :label="item.name">
              <el-select v-if="item.type=='select'" v-model="form_add[item.prop]" placeholder="请选择">
                <el-option
                  v-for="(it,i) in item.options"
                  :key="i"
                  :label="it[item.optionValue || 'value']"
                  :value="it[item.optionKey || 'key']">
                </el-option>
              </el-select>
              <template v-else-if="item.type=='img'">
                <el-upload
                  class="avatar-uploader"
                  :headers="{'authorization':token}"
                  :action="host+'/file/upload'"
                  name="files"
                  :on-success="uploadImgSuccess"
                  :show-file-list="false"
                  >
                  <img v-if="form_add[item.prop]" :src="host+form_add[item.prop]" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </template>
              <el-input v-else v-model="form_add[item.prop]"></el-input>
            </el-form-item>
          </template>
        </template>
      </el-form>
    </div>
    <span class="dialog_footer">
      <el-button @click="innerVisible = true">取 消</el-button>
      <el-button type="primary" @click="addSubmit">确 定</el-button>
    </span>
    <el-dialog
      title="提示"
      v-model="innerVisible"
      width="30%"
      top="10%"
      append-to-body
      :before-close="handleClose">
      <span>离开将丢失当前填写的内容</span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="innerVisible = false">取 消</el-button>
          <el-button type="primary" @click="closeCreateDialod">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
interface DateTypes{
  form_add:object,
  innerVisible:boolean,
}
export default defineComponent({
  props:{
    columnArr:{
      type:Array,
      default:[],
    },
    close:{
      type:Function,
      default:()=>{},
    },
    submit:{
      type:Function,
      default:()=>{},
    }
  },
  data():DateTypes{
    return {
      innerVisible:false,
      form_add:{},
    }
  },
  methods:{
    closeCreateDialod(){
      this.innerVisible = false;
      this.close();
    },
    addSubmit():void{
      this.submit(this.form_add)
    }

  }
})
</script>
<style lang="less" scoped>
.create_container{
  .dialog_footer{
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
}
</style>